const Router = require('koa-router');
const router = new Router();
router.prefix('/dic'); //路由前缀

//模型
const PcdModel = require("../models/dicPcd"); //省市区树
const voltageModel = require("../models/dicVoltage"); //电压等级

//省市区列表
router.post('/allPcd', async (ctx, next) => {
    //定义返回值
    let cb = [];
    //前端参数
    let req = ctx.request.body;
    try {
        let find = await PcdModel.find({});
        if (find) {
            cb = find;
        };
    } catch (e) {
        cb = [{
            value: "",
            label: "",
            children: []
        }];
    } finally {
        ctx.body = cb;
    }
});

//电压等级
router.post('/voltage', async (ctx, next) => {
    //定义返回值
    let cb = [];
    //前端参数
    let req = ctx.request.body;
    try {
        let find = await voltageModel.find({});
        if (find) {
            cb = find;
        };
    } catch (e) {
        cb = [{
            value: "",
            label: "",
            children: []
        }];
    } finally {
        ctx.body = cb;
    }
});

module.exports = router;